<template>
  <div>
    <div v-for="(report, index) in reportData" :key="index">
      <div class="listTitle">{{ report.groupName }}</div>
      <div class="listbox">
        <div v-for="(item, index) in report.items" :key="index" class="infobox">
          <div class="pctBox">{{ item.value }}</div>
          <div class="nameBox">{{ item.text }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
  import { ref, onMounted, inject } from 'vue'

  const $utils = inject('$utils')
  const reportData = ref([])

  function getReport () {
    $utils.post({
      url: '/Api/Report/StatGroups',
      showLoading: true,
      ok: (res) => {
        // console.log(res)
        reportData.value = res.data
      }
    })
  }

  const onMountedHook = () => {
    getReport()
  }

  onMounted(() => {
    onMountedHook()
  })
</script>

<style scoped>
  .listTitle {
    margin: 10px 0;
    font-size: 20px;
  }
  .listbox {
    display: flex;
    flex-wrap: wrap;
  }
  .infobox {
    flex-shrink: 0;
    width: 180px;
    height: 120px;
    margin-right: 15px;
    margin-bottom: 15px;
    border-radius: 10px;
    /* border: 1px solid #ccc; */
    box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #fff;
  }
  .pctBox {
    flex: 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    font-size: 30px;
    font-weight: bold;
    margin-top: 20px;
  }
  .nameBox {
    height: 45px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    font-size: 16px;
  }
</style>